package ntd.remote.file.action;

import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import lj.a.tool.LJToolFile;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.remote.file.bo.ComRemoteFileBO;
import ntd.remote.link.bo.MsgBO;

public class ActionRemoteList extends ActionAbs {

    public static final String ACTION_CODE = "action-netty-remote-file-loop-list";

    @Override
    public ActionInfo info() {
        return new ActionInfo("netty 远程文件列表操作", ACTION_CODE, this);
    }

    @Override
    public ActionOutBo handle() {
        MsgBO msgBOIn = actionInBo.getData().toBean(MsgBO.class);
        ComRemoteFileBO comRemoteFileBO = JSONUtil.toBean(msgBOIn.getData(), ComRemoteFileBO.class);

        StaticLog.info("netty 远程文件[{}]列表操作", comRemoteFileBO.getPath());

        return new ActionOutBo(CollStreamUtil.toList(LJToolFile.loopFiles(comRemoteFileBO.getPath()), ComRemoteFileBO::transform));
    }
}
